#pragma once

namespace TileMaker {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace System::IO;

	using namespace std;

	/// <summary>
	/// Summary for Form1
	/// </summary>

	static enum class colors{ D_Black = 33, D_Blue, D_Green, D_Teal, D_Red, D_Purple, D_Yellow, D_White, 
		L_Black, L_Blue, L_Green, L_Teal, L_Red, L_Purple, L_Yellow, L_White, Blank = -1};

	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:


		array< Button^, 2 >^ image;
		static int tileWidth = 0;
		static int tileHeight = 0;
		static String^ pathLoc = gcnew String("../Tiles");
		String^ loadedFile;

	private: System::Windows::Forms::Button^  Canvis_Creator;
	private: System::Windows::Forms::Button^  selectedColor_Button;
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Button^  Save_Button;
	private: System::Windows::Forms::Button^  Load_Button;
	private: System::Windows::Forms::ComboBox^  files_ComboBox;

	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::Label^  label5;
	private: System::Windows::Forms::ComboBox^  walkable_comboBox;

	private: System::Windows::Forms::Label^  label6;


	private: System::Windows::Forms::Timer^  timer1;
	public: 



		// Attributes

		//int currentColor;

		static colors currentColor = colors::Blank;



		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  D_Black_Button;
	protected: 

	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Button^  D_Blue_Button;
	private: System::Windows::Forms::Button^  D_Teal_Button;
	private: System::Windows::Forms::Button^  D_Green_Button;
	private: System::Windows::Forms::Button^  D_White_Button;
	private: System::Windows::Forms::Button^  D_Yellow_Button;
	private: System::Windows::Forms::Button^  D_Purple_Button;
	private: System::Windows::Forms::Button^  D_Red_Button;
	private: System::Windows::Forms::Button^  L_White_Button;
	private: System::Windows::Forms::Button^  L_Yellow_Button;
	private: System::Windows::Forms::Button^  L_Purple_Button;
	private: System::Windows::Forms::Button^  L_Red_Button;
	private: System::Windows::Forms::Button^  L_Teal_Button;
	private: System::Windows::Forms::Button^  L_Green_Button;
	private: System::Windows::Forms::Button^  L_Blue_Button;
	private: System::Windows::Forms::Button^  L_Black_Button;

	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::NumericUpDown^  imageWidth;
	private: System::Windows::Forms::NumericUpDown^  imageHeight;
	private: System::ComponentModel::IContainer^  components;


	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
			this->D_Black_Button = (gcnew System::Windows::Forms::Button());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->D_Blue_Button = (gcnew System::Windows::Forms::Button());
			this->D_Teal_Button = (gcnew System::Windows::Forms::Button());
			this->D_Green_Button = (gcnew System::Windows::Forms::Button());
			this->D_White_Button = (gcnew System::Windows::Forms::Button());
			this->D_Yellow_Button = (gcnew System::Windows::Forms::Button());
			this->D_Purple_Button = (gcnew System::Windows::Forms::Button());
			this->D_Red_Button = (gcnew System::Windows::Forms::Button());
			this->L_White_Button = (gcnew System::Windows::Forms::Button());
			this->L_Yellow_Button = (gcnew System::Windows::Forms::Button());
			this->L_Purple_Button = (gcnew System::Windows::Forms::Button());
			this->L_Red_Button = (gcnew System::Windows::Forms::Button());
			this->L_Teal_Button = (gcnew System::Windows::Forms::Button());
			this->L_Green_Button = (gcnew System::Windows::Forms::Button());
			this->L_Blue_Button = (gcnew System::Windows::Forms::Button());
			this->L_Black_Button = (gcnew System::Windows::Forms::Button());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->imageWidth = (gcnew System::Windows::Forms::NumericUpDown());
			this->imageHeight = (gcnew System::Windows::Forms::NumericUpDown());
			this->Canvis_Creator = (gcnew System::Windows::Forms::Button());
			this->selectedColor_Button = (gcnew System::Windows::Forms::Button());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->Save_Button = (gcnew System::Windows::Forms::Button());
			this->Load_Button = (gcnew System::Windows::Forms::Button());
			this->files_ComboBox = (gcnew System::Windows::Forms::ComboBox());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->label5 = (gcnew System::Windows::Forms::Label());
			this->walkable_comboBox = (gcnew System::Windows::Forms::ComboBox());
			this->label6 = (gcnew System::Windows::Forms::Label());
			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->imageWidth))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->imageHeight))->BeginInit();
			this->SuspendLayout();
			// 
			// D_Black_Button
			// 
			this->D_Black_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"D_Black_Button.Image")));
			this->D_Black_Button->Location = System::Drawing::Point(15, 60);
			this->D_Black_Button->Name = L"D_Black_Button";
			this->D_Black_Button->Size = System::Drawing::Size(20, 20);
			this->D_Black_Button->TabIndex = 33;
			this->D_Black_Button->UseVisualStyleBackColor = true;
			this->D_Black_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(12, 45);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(39, 13);
			this->label1->TabIndex = 1;
			this->label1->Text = L"Pallete";
			// 
			// D_Blue_Button
			// 
			this->D_Blue_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"D_Blue_Button.Image")));
			this->D_Blue_Button->Location = System::Drawing::Point(130, 60);
			this->D_Blue_Button->Name = L"D_Blue_Button";
			this->D_Blue_Button->Size = System::Drawing::Size(20, 20);
			this->D_Blue_Button->TabIndex = 34;
			this->D_Blue_Button->UseVisualStyleBackColor = true;
			this->D_Blue_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// D_Teal_Button
			// 
			this->D_Teal_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"D_Teal_Button.Image")));
			this->D_Teal_Button->Location = System::Drawing::Point(110, 60);
			this->D_Teal_Button->Name = L"D_Teal_Button";
			this->D_Teal_Button->Size = System::Drawing::Size(20, 20);
			this->D_Teal_Button->TabIndex = 36;
			this->D_Teal_Button->UseVisualStyleBackColor = true;
			this->D_Teal_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// D_Green_Button
			// 
			this->D_Green_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"D_Green_Button.Image")));
			this->D_Green_Button->Location = System::Drawing::Point(91, 60);
			this->D_Green_Button->Name = L"D_Green_Button";
			this->D_Green_Button->Size = System::Drawing::Size(20, 20);
			this->D_Green_Button->TabIndex = 35;
			this->D_Green_Button->UseVisualStyleBackColor = true;
			this->D_Green_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// D_White_Button
			// 
			this->D_White_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"D_White_Button.Image")));
			this->D_White_Button->Location = System::Drawing::Point(34, 79);
			this->D_White_Button->Name = L"D_White_Button";
			this->D_White_Button->Size = System::Drawing::Size(20, 20);
			this->D_White_Button->TabIndex = 40;
			this->D_White_Button->UseVisualStyleBackColor = true;
			this->D_White_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// D_Yellow_Button
			// 
			this->D_Yellow_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"D_Yellow_Button.Image")));
			this->D_Yellow_Button->Location = System::Drawing::Point(72, 60);
			this->D_Yellow_Button->Name = L"D_Yellow_Button";
			this->D_Yellow_Button->Size = System::Drawing::Size(20, 20);
			this->D_Yellow_Button->TabIndex = 39;
			this->D_Yellow_Button->UseVisualStyleBackColor = true;
			this->D_Yellow_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// D_Purple_Button
			// 
			this->D_Purple_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"D_Purple_Button.Image")));
			this->D_Purple_Button->Location = System::Drawing::Point(149, 60);
			this->D_Purple_Button->Name = L"D_Purple_Button";
			this->D_Purple_Button->Size = System::Drawing::Size(20, 20);
			this->D_Purple_Button->TabIndex = 38;
			this->D_Purple_Button->UseVisualStyleBackColor = true;
			this->D_Purple_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// D_Red_Button
			// 
			this->D_Red_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"D_Red_Button.Image")));
			this->D_Red_Button->Location = System::Drawing::Point(53, 60);
			this->D_Red_Button->Name = L"D_Red_Button";
			this->D_Red_Button->Size = System::Drawing::Size(20, 20);
			this->D_Red_Button->TabIndex = 37;
			this->D_Red_Button->UseVisualStyleBackColor = true;
			this->D_Red_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// L_White_Button
			// 
			this->L_White_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"L_White_Button.Image")));
			this->L_White_Button->Location = System::Drawing::Point(15, 79);
			this->L_White_Button->Name = L"L_White_Button";
			this->L_White_Button->Size = System::Drawing::Size(20, 20);
			this->L_White_Button->TabIndex = 48;
			this->L_White_Button->UseVisualStyleBackColor = true;
			this->L_White_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// L_Yellow_Button
			// 
			this->L_Yellow_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"L_Yellow_Button.Image")));
			this->L_Yellow_Button->Location = System::Drawing::Point(72, 79);
			this->L_Yellow_Button->Name = L"L_Yellow_Button";
			this->L_Yellow_Button->Size = System::Drawing::Size(20, 20);
			this->L_Yellow_Button->TabIndex = 47;
			this->L_Yellow_Button->UseVisualStyleBackColor = true;
			this->L_Yellow_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			this->L_Yellow_Button->DragOver += gcnew System::Windows::Forms::DragEventHandler(this, &Form1::L_Yellow_Button_DragOver);
			this->L_Yellow_Button->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::L_Yellow_Button_MouseMove);
			// 
			// L_Purple_Button
			// 
			this->L_Purple_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"L_Purple_Button.Image")));
			this->L_Purple_Button->Location = System::Drawing::Point(149, 79);
			this->L_Purple_Button->Name = L"L_Purple_Button";
			this->L_Purple_Button->Size = System::Drawing::Size(20, 20);
			this->L_Purple_Button->TabIndex = 46;
			this->L_Purple_Button->UseVisualStyleBackColor = true;
			this->L_Purple_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// L_Red_Button
			// 
			this->L_Red_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"L_Red_Button.Image")));
			this->L_Red_Button->Location = System::Drawing::Point(53, 79);
			this->L_Red_Button->Name = L"L_Red_Button";
			this->L_Red_Button->Size = System::Drawing::Size(20, 20);
			this->L_Red_Button->TabIndex = 45;
			this->L_Red_Button->UseVisualStyleBackColor = true;
			this->L_Red_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// L_Teal_Button
			// 
			this->L_Teal_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"L_Teal_Button.Image")));
			this->L_Teal_Button->Location = System::Drawing::Point(110, 79);
			this->L_Teal_Button->Name = L"L_Teal_Button";
			this->L_Teal_Button->Size = System::Drawing::Size(20, 20);
			this->L_Teal_Button->TabIndex = 44;
			this->L_Teal_Button->UseVisualStyleBackColor = true;
			this->L_Teal_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// L_Green_Button
			// 
			this->L_Green_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"L_Green_Button.Image")));
			this->L_Green_Button->Location = System::Drawing::Point(91, 79);
			this->L_Green_Button->Name = L"L_Green_Button";
			this->L_Green_Button->Size = System::Drawing::Size(20, 20);
			this->L_Green_Button->TabIndex = 43;
			this->L_Green_Button->UseVisualStyleBackColor = true;
			this->L_Green_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// L_Blue_Button
			// 
			this->L_Blue_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"L_Blue_Button.Image")));
			this->L_Blue_Button->Location = System::Drawing::Point(130, 79);
			this->L_Blue_Button->Name = L"L_Blue_Button";
			this->L_Blue_Button->Size = System::Drawing::Size(20, 20);
			this->L_Blue_Button->TabIndex = 42;
			this->L_Blue_Button->UseVisualStyleBackColor = true;
			this->L_Blue_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// L_Black_Button
			// 
			this->L_Black_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"L_Black_Button.Image")));
			this->L_Black_Button->Location = System::Drawing::Point(34, 60);
			this->L_Black_Button->Name = L"L_Black_Button";
			this->L_Black_Button->Size = System::Drawing::Size(20, 20);
			this->L_Black_Button->TabIndex = 41;
			this->L_Black_Button->UseVisualStyleBackColor = true;
			this->L_Black_Button->Click += gcnew System::EventHandler(this, &Form1::D_Black_Button_Click);
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(12, 14);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(35, 13);
			this->label2->TabIndex = 18;
			this->label2->Text = L"Width";
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(104, 14);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(38, 13);
			this->label3->TabIndex = 19;
			this->label3->Text = L"Height";
			// 
			// imageWidth
			// 
			this->imageWidth->Location = System::Drawing::Point(53, 12);
			this->imageWidth->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
			this->imageWidth->Name = L"imageWidth";
			this->imageWidth->Size = System::Drawing::Size(35, 20);
			this->imageWidth->TabIndex = 20;
			this->imageWidth->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {10, 0, 0, 0});
			// 
			// imageHeight
			// 
			this->imageHeight->Location = System::Drawing::Point(148, 12);
			this->imageHeight->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {1, 0, 0, 0});
			this->imageHeight->Name = L"imageHeight";
			this->imageHeight->Size = System::Drawing::Size(35, 20);
			this->imageHeight->TabIndex = 21;
			this->imageHeight->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {10, 0, 0, 0});
			// 
			// Canvis_Creator
			// 
			this->Canvis_Creator->Location = System::Drawing::Point(197, 47);
			this->Canvis_Creator->Name = L"Canvis_Creator";
			this->Canvis_Creator->Size = System::Drawing::Size(75, 23);
			this->Canvis_Creator->TabIndex = 22;
			this->Canvis_Creator->Text = L"Create";
			this->Canvis_Creator->UseVisualStyleBackColor = true;
			this->Canvis_Creator->Click += gcnew System::EventHandler(this, &Form1::Canvis_Creator_Click);
			// 
			// selectedColor_Button
			// 
			this->selectedColor_Button->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"selectedColor_Button.Image")));
			this->selectedColor_Button->Location = System::Drawing::Point(197, 76);
			this->selectedColor_Button->Name = L"selectedColor_Button";
			this->selectedColor_Button->Size = System::Drawing::Size(23, 23);
			this->selectedColor_Button->TabIndex = 48;
			this->selectedColor_Button->UseVisualStyleBackColor = true;
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(226, 76);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(145, 23);
			this->button1->TabIndex = 24;
			this->button1->Text = L"Fill with Selected";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// Save_Button
			// 
			this->Save_Button->Location = System::Drawing::Point(278, 47);
			this->Save_Button->Name = L"Save_Button";
			this->Save_Button->Size = System::Drawing::Size(75, 23);
			this->Save_Button->TabIndex = 25;
			this->Save_Button->Text = L"Save";
			this->Save_Button->UseVisualStyleBackColor = true;
			this->Save_Button->Click += gcnew System::EventHandler(this, &Form1::Save_Button_Click);
			// 
			// Load_Button
			// 
			this->Load_Button->Location = System::Drawing::Point(359, 47);
			this->Load_Button->Name = L"Load_Button";
			this->Load_Button->Size = System::Drawing::Size(75, 23);
			this->Load_Button->TabIndex = 26;
			this->Load_Button->Text = L"Load";
			this->Load_Button->UseVisualStyleBackColor = true;
			this->Load_Button->Click += gcnew System::EventHandler(this, &Form1::Load_Button_Click);
			// 
			// files_ComboBox
			// 
			this->files_ComboBox->FormattingEnabled = true;
			this->files_ComboBox->Location = System::Drawing::Point(241, 11);
			this->files_ComboBox->Name = L"files_ComboBox";
			this->files_ComboBox->Size = System::Drawing::Size(193, 21);
			this->files_ComboBox->TabIndex = 27;
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12));
			this->label4->Location = System::Drawing::Point(202, 9);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(33, 20);
			this->label4->TabIndex = 28;
			this->label4->Text = L"Tile";
			// 
			// label5
			// 
			this->label5->AutoSize = true;
			this->label5->Location = System::Drawing::Point(319, 108);
			this->label5->Name = L"label5";
			this->label5->Size = System::Drawing::Size(52, 13);
			this->label5->TabIndex = 29;
			this->label5->Text = L"Walkable";
			// 
			// walkable_comboBox
			// 
			this->walkable_comboBox->FormattingEnabled = true;
			this->walkable_comboBox->Items->AddRange(gcnew cli::array< System::Object^  >(2) {L"True", L"False"});
			this->walkable_comboBox->Location = System::Drawing::Point(377, 105);
			this->walkable_comboBox->Name = L"walkable_comboBox";
			this->walkable_comboBox->Size = System::Drawing::Size(51, 21);
			this->walkable_comboBox->TabIndex = 1;
			this->walkable_comboBox->Text = L"True";
			this->walkable_comboBox->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::walkable_comboBox_SelectedIndexChanged);
			// 
			// label6
			// 
			this->label6->AutoSize = true;
			this->label6->Location = System::Drawing::Point(262, 108);
			this->label6->Name = L"label6";
			this->label6->Size = System::Drawing::Size(51, 13);
			this->label6->TabIndex = 31;
			this->label6->Text = L"Tile Stats";
			// 
			// timer1
			// 
			this->timer1->Enabled = true;
			this->timer1->Interval = 5000;
			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(447, 466);
			this->Controls->Add(this->label6);
			this->Controls->Add(this->walkable_comboBox);
			this->Controls->Add(this->label5);
			this->Controls->Add(this->label4);
			this->Controls->Add(this->files_ComboBox);
			this->Controls->Add(this->Load_Button);
			this->Controls->Add(this->Save_Button);
			this->Controls->Add(this->button1);
			this->Controls->Add(this->selectedColor_Button);
			this->Controls->Add(this->Canvis_Creator);
			this->Controls->Add(this->imageHeight);
			this->Controls->Add(this->imageWidth);
			this->Controls->Add(this->label3);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->L_White_Button);
			this->Controls->Add(this->L_Yellow_Button);
			this->Controls->Add(this->L_Purple_Button);
			this->Controls->Add(this->L_Red_Button);
			this->Controls->Add(this->L_Teal_Button);
			this->Controls->Add(this->L_Green_Button);
			this->Controls->Add(this->L_Blue_Button);
			this->Controls->Add(this->L_Black_Button);
			this->Controls->Add(this->D_White_Button);
			this->Controls->Add(this->D_Yellow_Button);
			this->Controls->Add(this->D_Purple_Button);
			this->Controls->Add(this->D_Red_Button);
			this->Controls->Add(this->D_Teal_Button);
			this->Controls->Add(this->D_Green_Button);
			this->Controls->Add(this->D_Blue_Button);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->D_Black_Button);
			this->Cursor = System::Windows::Forms::Cursors::Default;
			this->Name = L"Form1";
			this->Text = L"Tile Maker";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->imageWidth))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->imageHeight))->EndInit();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion


		void ListFiles()
		{
			files_ComboBox->Items->Clear();
			DirectoryInfo^ di = gcnew DirectoryInfo(pathLoc);
			DirectoryInfo^ inner;
			//FileInfo^ files[];
			//FileInfo^ folders[] = di.GetDirectories();
			array< FileInfo^, 1 >^ files;
			array< DirectoryInfo^, 1 >^ folders;
			folders = di->GetDirectories();
				for (int i = 0; i < folders->Length; i++)
				{
					inner = gcnew DirectoryInfo(pathLoc + "/" + folders[i]->Name);

					 files = inner->GetFiles();
					 for (int j = 0; j < files->Length; j++)
					 {
						 if (files[j]->Name->StartsWith("_"))
							 files_ComboBox->Items->Add(folders[i]->Name + files[j]->Name);
					 }
				}

		}   

	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) 
	{
		ListFiles();
	}

		// Button event
		private: System::Void D_Black_Button_Click(System::Object^  sender, System::EventArgs^  e) 
		 {
			 Button^ btn = dynamic_cast<Button^>(sender);
			 String^ s = btn->Name;

			 selectedColor_Button->Image = btn->Image;
			 selectedColor_Button->TabIndex = btn->TabIndex;
			 currentColor = colors(selectedColor_Button->TabIndex);

		 }
		private: System::Void Canvis_Button_Click(System::Object^  sender, System::EventArgs^  e) 
		{
			Button^ btn = dynamic_cast<Button^>(sender);

			btn->TabIndex = selectedColor_Button->TabIndex;
			btn->Image = selectedColor_Button->Image;
		}

private: System::Void Canvis_Creator_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(tileHeight)
				 for (int i = 0 ; i < tileHeight; i++)
				 {
					 for (int j = 0; j < tileWidth; j++) {
						 this->Controls->Remove(this->image[i,j]);
					 }
				 }

			 tileHeight = (int)imageHeight->Value;
			 tileWidth = (int)imageWidth->Value;

				
			 image = gcnew array< Button^, 2 >((int)imageHeight->Value, (int)imageWidth->Value);

			 for (int i = 0 ; i < imageHeight->Value ; i++)
				 for (int j = 0 ; j < imageWidth->Value ; j++) {

					 image[i,j] = gcnew Button;

					 image[i,j]->Size = System::Drawing::Size(20, 20);
					 image[i,j]->Location = System::Drawing::Point(15 + 20 * j, 120 + 20 * i);
					 image[i,j]->UseVisualStyleBackColor = false;
					 image[i,j]->Name = "" + i + "," + j;
					 image[i,j]->Click += gcnew System::EventHandler(this, &Form1::Canvis_Button_Click);
					 this->Controls->Add(this->image[i,j]);
					 image[i,j]->Image = L_White_Button->Image;
					 image[i,j]->TabIndex = L_White_Button->TabIndex;
					 
				 }
		 }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
		 {
			 for (int i = 0 ; i < tileHeight ; i++)
				 for (int j = 0 ; j < tileWidth ; j++) {

					 image[i,j]->Image = selectedColor_Button->Image;
					 image[i,j]->TabIndex = selectedColor_Button->TabIndex;
				 }
		 }
private: System::Void Save_Button_Click(System::Object^  sender, System::EventArgs^  e)
		 {
			 String^ data;

			 char ascii;

			 try 
			 {

				 loadedFile = files_ComboBox->Text;
				 String^ fullLoc = pathLoc+"/" + loadedFile->Substring(0,loadedFile->IndexOf('_'));

				 // Delete _ files
				 DirectoryInfo^ inner = gcnew DirectoryInfo(fullLoc);

				 array< FileInfo^, 1 >^ files;


				 files = inner->GetFiles();
				 for (int j = 0; j < files->Length; j++)
				 {
					 if (files[j]->Name->StartsWith("_"))
						 File::Delete(fullLoc + "/" + files[j]->Name);
				 }


				 System::IO::Directory::CreateDirectory("..\\Tiles\\" + loadedFile->Substring(0,loadedFile->IndexOf('_')));



				 StreamWriter^ myfile = gcnew StreamWriter(fullLoc + "/image.txt");

				 char^ chars;

				 myfile->WriteLine("0");
				 myfile->WriteLine("0");

				 myfile->WriteLine(tileWidth);

				 myfile->WriteLine(tileHeight);

				 for (int i = 0 ; i < tileHeight ; i++)
				 {
					 data = "";
					 for (int j = 0 ; j < tileWidth ; j++) {

						 myfile->Write(char(image[i,j]->TabIndex));
					 }
					 myfile->WriteLine("");
				 }



				 myfile->Close();

				 myfile = gcnew StreamWriter(fullLoc + "/" + loadedFile->Substring(loadedFile->IndexOf('_')));

				 myfile->WriteLine("");

				 myfile->Close();

				 myfile = gcnew StreamWriter(fullLoc + "/data.txt");
				  myfile->WriteLine("" + walkable_comboBox->TabIndex);///+ walkable_comboBox->i);
				   myfile->Close();

			 }
			 catch(System::Exception^ e)
			 {
				 int i = 3;
			 }
			 ListFiles();
		 }

		 Image^ getImageByNumber(int tab)
		 {
			 if(tab == (int)colors::D_Black)
				 return D_Black_Button->Image;
			 else if(tab == (int)colors::D_Blue)
				 return D_Blue_Button->Image;
			 else if(tab == (int)colors::D_Green)
				 return D_Green_Button->Image;
			 else if(tab == (int)colors::D_Teal)
				 return D_Teal_Button->Image;
			 else if(tab == (int)colors::D_Red)
				 return D_Red_Button->Image;
			 else if(tab == (int)colors::D_Purple)
				 return D_Purple_Button->Image;
			 else if(tab == (int)colors::D_Yellow)
				 return D_Yellow_Button->Image;
			 else if(tab == (int)colors::D_White)
				 return D_White_Button->Image;
			 ////////////////////////////////////////////
			 else if(tab == (int)colors::L_Black)
				 return L_Black_Button->Image;
			 else if(tab == (int)colors::L_Blue)
				 return L_Blue_Button->Image;
			 else if(tab == (int)colors::L_Green)
				 return L_Green_Button->Image;
			 else if(tab == (int)colors::L_Teal)
				 return L_Teal_Button->Image;
			 else if(tab == (int)colors::L_Red)
				 return L_Red_Button->Image;
			 else if(tab == (int)colors::L_Purple)
				 return L_Purple_Button->Image;
			 else if(tab == (int)colors::L_Yellow)
				 return L_Yellow_Button->Image;
			 else if(tab == (int)colors::L_White)
				 return L_White_Button->Image;



			 return L_White_Button->Image;
		 }
private: System::Void Load_Button_Click(System::Object^  sender, System::EventArgs^  e) 
		 {

			 if(tileHeight)
				 for (int i = 0 ; i < tileHeight; i++)
				 {
					 for (int j = 0; j < tileWidth; j++) 
					 {
						 this->Controls->Remove(this->image[i,j]);
					 }
				 }

				String^ data;
			
			 
			 try 
			 {
				

				 loadedFile = files_ComboBox->Text;
				 String^ fullLoc = pathLoc+"/" + loadedFile->Substring(0,loadedFile->IndexOf('_'));



				 StreamReader^ myfile = gcnew StreamReader(fullLoc + "/image.txt");

				 data = myfile->ReadLine();
				 data = myfile->ReadLine();

				 data = myfile->ReadLine();
				 tileWidth =  System::Int32::Parse(data);
				 imageWidth->Value = tileWidth;

				 data = myfile->ReadLine();
				 tileHeight =  System::Int32::Parse(data);
				 imageHeight->Value = tileHeight;


					 tileHeight = (int)imageHeight->Value;
					 tileWidth = (int)imageWidth->Value;


					 image = gcnew array< Button^, 2 >((int)imageHeight->Value, (int)imageWidth->Value);

					 for (int i = 0 ; i < imageHeight->Value ; i++)
					 {
						 data = myfile->ReadLine();
						 for (int j = 0 ; j < imageWidth->Value ; j++) {


							 image[i,j] = gcnew Button;

							 image[i,j]->Size = System::Drawing::Size(20, 20);
							 image[i,j]->Location = System::Drawing::Point(15 + 20 * j, 120 + 20 * i);
							 image[i,j]->UseVisualStyleBackColor = false;
							 image[i,j]->Name = "" + i + "," + j;
							 image[i,j]->Click += gcnew System::EventHandler(this, &Form1::Canvis_Button_Click);
							 this->Controls->Add(this->image[i,j]);
							 image[i,j]->TabIndex = data[j];
							 image[i,j]->Image = getImageByNumber(data[j]);

						 }
					 }



					 myfile->Close();


					 myfile = gcnew StreamReader(fullLoc + "/data.txt");

					 data = myfile->ReadLine();
					 if(System::Int32::Parse(data) == 0)
					 {
						 walkable_comboBox->Text = "False";
					 }
					 else
						 walkable_comboBox->Text = "True";

					 myfile->Close();

			 }
			 catch(System::Exception^ e)
			 {
				 int i = 3;
			 }


		 }
		 
	private: System::Void L_Yellow_Button_DragOver(System::Object^  sender, System::Windows::Forms::DragEventArgs^  e)
	{
			int i =3;
	}
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) 
		 {
			// this->i
			//	brush_Button ->Location = System::Drawing::Point(Cursor->Position.X - this->Location.X - 9,Cursor->Position.Y - this->Location.Y - 29);
			 if (0)
			 {
				 if(Cursor->Position.X - this->Location.X > 15 && Cursor->Position.X - this->Location.X < 15 + 20 * tileWidth)
				 {
					 if(Cursor->Position.Y - this->Location.Y > 120 && Cursor->Position.Y - this->Location.Y < 120 + 20 * tileHeight)
					 {
						// Button^ btn = dynamic_cast<Button^>(sender);

						// btn->TabIndex = selectedColor_Button->TabIndex;
						 //btn->Image = selectedColor_Button->Image;
					 }
				 }
			 }



		 }
private: System::Void L_Yellow_Button_MouseHover(System::Object^  sender, System::EventArgs^  e) 
		 {
			if(0 == (int)System::Windows::Forms::MouseButtons::Left)
			{
				Button^ btn = dynamic_cast<Button^>(sender);

				btn->TabIndex = selectedColor_Button->TabIndex;
				btn->Image = selectedColor_Button->Image;
			}

		 }
private: System::Void L_Yellow_Button_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) 
		 {

		 }
private: System::Void walkable_comboBox_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 ComboBox^ cb = dynamic_cast<ComboBox^>(sender);

			 if(cb->Text == ("True"))
				cb->TabIndex = 1;
			 else
				 cb->TabIndex = 0;
			
		 }
};
}

